﻿///////////////////////////////////////
//////add by yl 2014年8月20日14:01:31
//////主要功能:处理班组设备报修
///////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Catering_DBOpertion;

namespace Catering_Model
{
    /// <summary>
    /// EMASppPlan:班组设备报修单
    /// </summary>
    [Serializable]
    public partial class ContratorMember
    {
        public ContratorMember()
        { }
        #region Model
        private int _id;
        private int _CID;
        private string _CName;
        private string _GroupID;
        private string _ClassID;
        private string _CardNo;
        private string _JobCard;
        private string _Effective;
        private string _Tel;
        private string _ConDesc;
        private string _gongzhong;
        private string _OldClassID;
        private string _OldGroupID;
        private DateTime _ChangeClassDate;
        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        ///承包商ID
        /// </summary>
        public int CID
        {
            set { _CID = value; }
            get { return _CID; }
        }
        /// <summary>
        /// 承包商姓名
        /// </summary>
        public string CName
        {
            set { _CName = value; }
            get { return _CName; }
        }
        /// <summary>
        /// 作业区编号
        /// </summary>
        public string GroupID
        {
            set { _GroupID = value; }
            get { return _GroupID; }
        }
        /// <summary>
        /// 班组编号
        /// </summary>
        public string ClassID
        {
            set { _ClassID = value; }
            get { return _ClassID; }
        }
        /// <summary>
        /// 跟踪卡号
        /// </summary>
        public string CardNo
        {
            set { _CardNo = value; }
            get { return _CardNo; }
        }

        /// <summary>
        /// 工作证件名称
        /// </summary>
        public string JobCard
        {
            set { _JobCard = value; }
            get { return _JobCard; }
        }
        /// <summary>
        /// 工作证有效区间
        /// </summary>
        public string Effective
        {
            set { _Effective = value; }
            get { return _Effective; }
        }
        /// <summary>
        /// 电话
        /// </summary>
        public string Tel
        {
            set { _Tel = value; }
            get { return _Tel; }
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string ConDesc
        {
            set { _ConDesc = value; }
            get { return _ConDesc; }
        }
        /// <summary>
        /// 工种
        /// </summary>
        public string gongzhong
        {
            set { _gongzhong = value; }
            get { return _gongzhong; }
        }
        /// <summary>
        /// 原班组
        /// </summary>
        public string OldClassID
        {
            set { _OldClassID = value; }
            get { return _OldClassID; }
        }
        /// <summary>
        /// 原负责作业区编号
        /// </summary>
        public string OldGroupID
        {
            set { _OldGroupID = value; }
            get { return _OldGroupID; }
        }
        /// <summary>
        /// 转班组时间
        /// </summary>
        public DateTime ChangeClassDate
        {
            set { _ChangeClassDate = value; }
            get { return _ChangeClassDate; }
        }
      
        #endregion Model
    }
}
namespace Catering_Rules
{
    /// <summary>
    /// Moon
    /// </summary>
    public partial class ContratorMember
    {
        private readonly Catering_Operation.ContratorMember dal = new Catering_Operation.ContratorMember();
        public ContratorMember()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.ContratorMember model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.ContratorMember model)
        {
            return dal.Update(model);
        }
        public bool Update(Catering_Model.ContratorMember model, string str)
        {
            return dal.Update(model,str);
        }
        public bool Update(Catering_Model.ContratorMember model, string str, string str1)
        {
            return dal.Update(model, str, str1);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContratorMember GetModel(int Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContratorMember> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.ContratorMember> DataTableToList(DataTable dt)
        {
            List<Catering_Model.ContratorMember> modelList = new List<Catering_Model.ContratorMember>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.ContratorMember model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Moon
    /// </summary>
    public partial class ContratorMember
    {
        public ContratorMember()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Moon");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.ContratorMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ContractorInfo(");
            strSql.Append("CID,CName,GroupID,ClassID,CardNo,JobCard,Effective,Tel,ConDesc,gongzhong,OldClassID,OldGroupID,ChangeClassDate)");
            strSql.Append(" values (");
            strSql.Append("@CID,@CName,@GroupID,@ClassID,@CardNo,@JobCard,@Effective,@Tel,@ConDesc,@gongzhong,@OldClassID,@OldGroupID,@ChangeClassDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@CID", SqlDbType.Int,-1),
                    new SqlParameter("@CName", SqlDbType.VarChar,50),
                    new SqlParameter("@GroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@CardNo", SqlDbType.VarChar,50),
                    new SqlParameter("@JobCard", SqlDbType.VarChar,50),
                    new SqlParameter("@Effective", SqlDbType.VarChar,50),
                    new SqlParameter("@Tel", SqlDbType.VarChar,50),
                    new SqlParameter("@ConDesc", SqlDbType.Text,-1),
                    new SqlParameter("@gongzhong", SqlDbType.VarChar,50),
                    new SqlParameter("@OldClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@OldGroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ChangeClassDate", SqlDbType.Date,-1)};
            parameters[0].Value = model.CID;
            parameters[1].Value = model.CName;
            parameters[2].Value = model.GroupID;
            parameters[3].Value = model.ClassID;
            parameters[4].Value = model.CardNo;
            parameters[5].Value = model.JobCard;
            parameters[6].Value = model.Effective;
            parameters[7].Value = model.Tel;           
            parameters[8].Value = model.ConDesc;
            parameters[9].Value = model.gongzhong;
            parameters[10].Value = model.OldClassID;
            parameters[11].Value = model.OldGroupID;
            parameters[12].Value = model.ChangeClassDate;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 转班组
        /// </summary>
         public bool Update(Catering_Model.ContratorMember model,string str)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ContractorInfo set ");
            strSql.Append("GroupID=@GroupID,");
            strSql.Append("ClassID=@ClassID,");
            strSql.Append("OldGroupID=@OldGroupID,");
            strSql.Append("OldClassID=@OldClassID,");
            strSql.Append("ChangeClassDate=@ChangeClassDate");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {                    
                    new SqlParameter("@GroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@OldGroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@OldClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@ChangeClassDate", SqlDbType.VarChar,50),                  
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.GroupID;
            parameters[1].Value = model.ClassID;
            parameters[2].Value = model.OldGroupID;
            parameters[3].Value = model.OldClassID;
            parameters[4].Value = model.ChangeClassDate;
            parameters[5].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
         /// <summary>
         /// 返陆地
         /// </summary>
         public bool Update(Catering_Model.ContratorMember model, string str,string str1)
         {
             StringBuilder strSql = new StringBuilder();
             strSql.Append("update ContractorInfo set ");
             strSql.Append("GroupID=@GroupID,");
             strSql.Append("ClassID=@ClassID,");
             strSql.Append("ChangeClassDate=@ChangeClassDate");
             strSql.Append(" where Id=@Id");
             SqlParameter[] parameters = {                    
                    new SqlParameter("@GroupID", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),                    
                    new SqlParameter("@ChangeClassDate", SqlDbType.VarChar,50),                  
                    new SqlParameter("@Id", SqlDbType.Int,4)};
             parameters[0].Value = model.GroupID;
             parameters[1].Value = model.ClassID;            
             parameters[2].Value = model.ChangeClassDate;
             parameters[3].Value = model.Id;

             int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
             if (rows > 0)
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
        public bool Update(Catering_Model.ContratorMember model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ContractorInfo set ");
            strSql.Append("CName=@CName,");
            strSql.Append("ClassID=@ClassID,");
            strSql.Append("CardNo=@CardNo,");
            strSql.Append("JobCard=@JobCard,");
            strSql.Append("Effective=@Effective,");
            strSql.Append("Tel=@Tel,");
            strSql.Append("ConDesc=@ConDesc,");
            strSql.Append("gongzhong=@gongzhong,");
            strSql.Append("OldClassID=@OldClassID,");
            strSql.Append("ChangeClassDate=@ChangeClassDate");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {                    
                    new SqlParameter("@CName", SqlDbType.VarChar,50),
                    new SqlParameter("@ClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@CardNo", SqlDbType.VarChar,50),
                    new SqlParameter("@JobCard", SqlDbType.VarChar,50),
                    new SqlParameter("@Effective", SqlDbType.VarChar,50),
                    new SqlParameter("@Tel", SqlDbType.VarChar,50),
                    new SqlParameter("@ConDesc", SqlDbType.VarChar,50),
                    new SqlParameter("@gongzhong", SqlDbType.VarChar,50),
                    new SqlParameter("@OldClassID", SqlDbType.VarChar,50),
                    new SqlParameter("@ChangeClassDate", SqlDbType.Date,-1),                    
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.CName;
            parameters[1].Value = model.ClassID;
            parameters[2].Value = model.CardNo;
            parameters[3].Value = model.JobCard;
            parameters[4].Value = model.Effective;
            parameters[5].Value = model.Tel;
            parameters[6].Value = model.ConDesc;
            parameters[7].Value = model.gongzhong;
            parameters[8].Value = model.OldClassID;
            parameters[9].Value = model.ChangeClassDate;
            parameters[10].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from ContractorInfo ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Moon ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContratorMember GetModel(int Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,CName,OldClassID,ClassID,CardNo,JobCard,Effective,Tel,ConDesc,gongzhong from ContractorInfo ");
            strSql.Append(" where id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            Catering_Model.ContratorMember model = new Catering_Model.ContratorMember();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }



        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.ContratorMember DataRowToModel(DataRow row)
        {
            Catering_Model.ContratorMember model = new Catering_Model.ContratorMember();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.Id = int.Parse(row["id"].ToString());
                }
                if (row["CName"] != null && row["CName"].ToString() != "")
                {
                    model.CName = row["CName"].ToString();
                }
                if (row["OldClassID"] != null && row["OldClassID"].ToString() != "")
                {
                    model.OldClassID = row["OldClassID"].ToString();
                }
                if (row["ClassID"] != null && row["ClassID"].ToString() != "")
                {
                    model.ClassID = row["ClassID"].ToString();
                }
                if (row["CardNo"] != null && row["CardNo"].ToString() != "")
                {
                    model.CardNo = row["CardNo"].ToString();
                }
                if (row["JobCard"] != null && row["JobCard"].ToString() != "")
                {
                    model.JobCard = row["JobCard"].ToString();
                }
                if (row["Effective"] != null && row["Effective"].ToString() != "")
                {
                    model.Effective = row["Effective"].ToString();
                }
                if (row["Tel"] != null && row["Tel"].ToString() != "")
                {
                    model.Tel = row["Tel"].ToString();
                }
                if (row["ConDesc"] != null && row["ConDesc"].ToString() != "")
                {
                    model.ConDesc = row["ConDesc"].ToString();
                }
                if (row["gongzhong"] != null && row["gongzhong"].ToString() != "")
                {
                    model.gongzhong = row["gongzhong"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select *");
            strSql.Append(" FROM ContractorInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Id,MoonName,ClassId,Remark ");
            strSql.Append(" FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Moon ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from Moon T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Moon";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}